<!-- 阶段表单弹窗 -->
<form id="stage-sys-form" lay-filter="stage-sys-form" class="layui-form model-form">
    <input name="stcode" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">阶段名</label>
        <div class="layui-input-block">
            <input name="stitle" placeholder="请输入体系名" type="text" class="layui-input"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所属体系</label>
        <div class="layui-input-block">
            <select name="tsysId" id="tsysId">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <textarea name="stades" placeholder="请输入描述内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">预计天数</label>
        <div class="layui-input-block">
            <input name="stesti" placeholder="请输入预计停留天数" type="text" class="layui-input"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input name="sorder" type="text" class="layui-input"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">验收标准</label>
        <div class="layui-input-block">
            <textarea name="stcrit" id="stcrit" placeholder="请输入描述内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="study-sys-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form', 'formSelects','layedit'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;
        var formSelects = layui.formSelects;
        var layedit = layui.layedit;

        //富文本框
        layedit.build('stcrit',{
            height:180
        });

        //获取所有体系
        admin.req('api-study/teachingSys/getList',{page:-1,limit:-1},function (data){
            if (data.code === 0){
                data = data.data;
                for (var i=0;i<data.length;i++){
                    $("#tsysId").append("<option value=\""+data[i].tcstid+"\">"+data[i].ttitle+"</option>");
                }
                form.render('select');
                // 回显数据
                var stage = admin.getTempData('t_stage_sys');
                console.log(stage);
                $('#stage-sys-form').attr('method', 'POST');
                if (stage) {
                    form.val('stage-sys-form', stage);
                    $('#stage-sys-form').attr('method', 'POST');
                }
            }else {
                layer.msg('获取体系失败', {icon: 2, time: 1000});
            }
        },'GET');


        // 表单提交事件
        form.on('submit(stage-sys-form-submit)', function (data) {
            layer.load(2);
            if (data.field.stcode    === ''){
                admin.req('api-study/stage/insert', JSON.stringify(data.field), function (data) {
                    layer.closeAll('loading');
                    if (data.code === 0) {
                        layer.msg(data.msg, {icon: 1, time: 500});
                        admin.finishPopupCenter();
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 500});
                    }
                }, 'POST');
            }else {
                admin.req('api-study/stage/update', JSON.stringify(data.field), function (data) {
                    layer.closeAll('loading');
                    if (data.code === 0) {
                        layer.msg(data.msg, {icon: 1, time: 500});
                        admin.finishPopupCenter();
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 500});
                    }
                }, 'POST');
            }

            return false;
        });
    });
</script>